#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char* a1 = NULL;
    char* a2 = NULL;
    a1 = (char*)malloc(10 * sizeof(char));
    strcpy(a1, "data.bian");  // 将字符串"data.bian"复制给a1
    a2 = (char*)malloc(10 * sizeof(char));
    strcpy(a2, "cheng.net");
    int lengthA1 = strlen(a1);  // a1串的长度
    int lengthA2 = strlen(a2);  // a2串的长度
    // 将两串合并到a1，空间不够则使用realloc动态开辟
    if(lengthA1 < lengthA1 + lengthA2)
    {
        a1 = (char*)realloc(a1, (lengthA1 + lengthA2) * sizeof(char));
    }
    for(int i=lengthA1;i<lengthA1+lengthA2; i++)
    {
        a1[i] = a2[i - lengthA1];
    }
    // 最后串的末尾要添加\0， 避免出错
    a1[lengthA1+lengthA2] = '\0';
    printf("%s\n", a1);
    // 释放空间
    free(a1);
    free(a2);
    return 0;
}